package com.wl.dzt.sys.core.dao.mate;


import com.wl.dzt.sys.util.StringUtil;

/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/5/005
 * @description 数据库列
 */
public class DataMateColumn {
    /**
     * 字段名称
     */
    private String fieldName;

    /**
     * 数据库字段名称
     */
    private String columnName;

    /**
     * 所属表格
     */
    private String parentTable;

    /**
     * 所属类
     */
    private Class<?> parentClazz;

    /**
     * 生成sql时候的名
     */
    private String sqlName;

    /**
     * 中文名
     */
    private String text;

    /**
     * 最大长度
     */
    private int maxLength;

    /**
     * 延迟加载
     */
    private boolean lazy;

    /**
     * <b>根据字段映射获取取了别名后的字段</b>
     * <p>
     * 别名规则为 实体对象中的.替换为_
     * </p>
     *
     * @param field 字段名称
     * @return 字段的别名
     */
    public String asFieldName(String field) {
        String frist = StringUtil.getStringFilterLast(field, "_");
        return (frist == null ? parentTable : frist) + "." + this.columnName;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getParentTable() {
        return parentTable;
    }

    public void setParentTable(String parentTable) {
        this.parentTable = parentTable;
    }

    public Class<?> getParentClazz() {
        return parentClazz;
    }

    public void setParentClazz(Class<?> parentClazz) {
        this.parentClazz = parentClazz;
    }

    public String getSqlName() {
        return sqlName;
    }

    public void setSqlName(String sqlName) {
        this.sqlName = sqlName;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int getMaxLength() {
        return maxLength;
    }

    public void setMaxLength(int maxLength) {
        this.maxLength = maxLength;
    }

    public boolean isLazy() {
        return lazy;
    }

    public void setLazy(boolean lazy) {
        this.lazy = lazy;
    }

}
